<!--设置模块唯一ID-->
<div id="cyy_datingshangpuguanli_caiwuqueren_modify">
<!--标题、面包屑-->
<section class="content-header">
    <h1>
        租赁财务确认
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li>产业园</li>
        <li>大厅商铺管理</li>
        <li>财务</li>
        <li class="active">租赁财务确认</li>
    </ol>
</section>
<!--列表-->
<section class="content">

</section>
<!--添加、修改弹出层-->
<script type="text/template" data-for="tp_editor">
    <form role="form" class="form-horizontal">
        <div class="u-area">
            <div class="form-group">
                <label class="col-sm-2 control-label">摊位号</label>
                <div class="col-sm-4">
                    <input type="text" class="form-control" name="p1" disabled
                           value="<%=data.p3?data.p1:''%>">
                </div>

                <label class="col-sm-2 control-label">客户姓名</label>
                <div class="col-sm-4">
                    <input type="text" class="form-control" name="p4" disabled
                           value="<%=data.p4?data.p4:''%>">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2"></div>
                <div class="col-sm-10">
                    <table class="table table-bordered table-striped table-hover"></table>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">合计抵消金额</label>
                <div class="col-sm-4">
                    <input type="text" class="form-control" name="p3" disabled
                           value="0">
                </div>

                <label class="col-sm-2 control-label">应缴金额</label>
                <div class="col-sm-4">
                    <input type="text" class="form-control" name="p4" disabled
                           value="<%=data.p4?data.p4:''%>">
                </div>
            </div>
            <div class="box-footer">
                <button type="submit" class="btn btn-primary pull-right">确认</button>
            </div>
        </div>
    </form>
</script>

<script>
    USEN(function () {
        //模块ID(全系统唯一)
        var tableId = "#cyy_datingshangpuguanli_caiwuqueren";
        var id = "#cyy_datingshangpuguanli_caiwuqueren_modify";

        //定义页面变量
        var $el = $(id);
        var $editor = $el.children('script[data-for=tp_editor]');

        $.ajax({
            url:"./simdata/common_modify_action.json",
            success:function(data){
                $el.children(".content").html(function(){
                    return _.template($editor.html())({
                        data:data
                    })
                });

                var selfTable = new USEN.Datatable({
                    //设置ID
                    "id": id+' table.table',
                    //配置服务
                    "ajax": "./simdata/common_table_ation.json",
                    //每行"操作"自定义action按钮回调
                    onItemAction: function ($tr, action) {
                    },
                    //列设置
                    "columns": [
                        { "title": "", "data": null, bSortable: false, render: function (data, type, full, meta) {
                            return  "<input type='checkbox' name='selectRow' data-item-action='modify'/>"
                        }},
                        { "title": "名称", "data": "p0"},
                        { "title": "数量", "data": "p1"},
                        { "title": "单价", "data": "p2"},
                        { "title": "小计", "data": "p3"},
                        { "title": "取花单位", "data": "p4"}
                    ],
                    "paging": false,
                    "searching": false,
                    "ordering": false,
                    "info": false,
                    select:null,
                    pageLength:9999,
                    onInit:function(e,dt){
                        var $dt = $(dt.nTableWrapper);
                        var $that = $(this);
                        $dt.find("thead:first th:first").append(function(){
                            return "<input type='checkbox' name='selectRow' data-item-action='modify'/>"
                        });
                        $dt.find('thead input:checkbox').on('change',function(){
                            if($(this).is(":checked")){
                                $dt.find("tbody input:checkbox").prop("checked",true);
                            }else{
                                $dt.find("tbody input:checkbox").prop("checked",false);
                            }
                        });
                        $dt.find('input:checkbox').on('change',function(){
                            var _i = 0;
                            $dt.find('tbody tr').each(function(i,j){
                                if($(j).find('td:first input:checked').length > 0)
                                    _i += parseFloat($(j).find('td:eq(4)').text())
                            });
                            $el.find("[name=p3]").val(_i)
                        })
                    }
                });

                //提交表单
                $el.find("form").ajaxForm({
                    url: './simdata/common_modify_action.json',
                    beforeSubmit: function (data) {
                        //console.log("数据提交之前.")
                    },
                    success: function (data, state, obj) {
                        USEN.notifyAlert({
                            title: "提示:",
                            content: '操作成功,刷新列表'
                        });
                        USEN.getDatatable(tableId + ' table.table').ajax.reload();
                        USEN.closeActiveTab();
                    }
                });

                $el.find("select").css('width','98%').select2({
                    dropdownParent:$el
                });
                $el.find("input[data-plugin=date]").datepicker({
                    autoclose: true
                });
            }
        })

    });
</script>
</div>